package com.kikcn.demo.security;

import com.kikcn.demo.dao.UserRepository;
import com.kikcn.demo.domain.Resource;
import com.kikcn.demo.domain.Role;
import com.kikcn.demo.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;


public class MyUserDetailServiceImpl implements UserDetailsService {

    @Autowired
    private UserRepository usersDao;

    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        User user  = this.usersDao.findByName(username);
        if (user  == null) {
            throw new UsernameNotFoundException(username);
        }

        return user ;
    }

}